package basic

import "fmt"

func pop() {
	s1 := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	// 弹出第一个
	front := s1[0]
	afterFront := s1[1:]
	fmt.Println(front, afterFront, s1)
	// 弹出最后一个
	tail := s1[len(s1)-1]
	afterTail := s1[:len(s1)-1]
	fmt.Println(tail, afterTail, s1)

	fmt.Println("===删除中间的5===")
	var index int
	for i, v := range s1 {
		if v == 5 {
			index = i
		}
	}
	afterDelete := append(s1[:index], s1[index+1:]...)
	fmt.Println(afterDelete)
}

func createSlice() {
	s1 := []int{2, 4, 6, 8}
	s2 := make([]int, 5)
	s3 := make([]int, 5, 10)
	copy(s3, s1)
	fmt.Println(len(s1), cap(s1))
	fmt.Println(len(s2), cap(s2))
	fmt.Println(s3, len(s3), cap(s3))
}

func updateArr(arr []int) {
	arr[1] = 99
	fmt.Println(arr)
}

func main() {
	pop()
	//createSlice()
	/*切片 是视图*/
	/*
		var arr = [...]int{0,1,2,3,4}
		s1 := arr[:]
		s2 := arr[2:]
		s3 := arr[3:5]

		fmt.Println(s1,s2,s3)
		updateArr(s3)*/
}
